# Which compiler
# CC = gcc
# AR = ar
# AT = @

include $(PROJ_ROOT_PATH)/config.mk

OUTPUT = SmartCar

# source file
SRCS += main.c
SRCS += comm.c
# SRCS += smartcar_protocol.c
# SRCS += mplink_test.c
# SRCS += syscom_test.c
# SRCS += microecc_test.c
# SRCS += curve25519_test.c
# SRCS += slink.c

OBJS = $(patsubst %.c,%.o,$(SRCS))

# LIBS += -lpthread
# LIBS += -lsyscom
# LIBS += -lbipbuffer
# LIBS += -lmicroecc
# LIBS += -lcurve25519
LIBS += -lbcm2835
LIBS += -li2c
LIBS += -lspi
LIBS += -lpca9685
LIBS += -lps2

# Where are include files kept
INCLUDES += -I$(MIDDLEWARE_PATH)
# INCLUDES += -I$(MIDDLEWARE_PATH)/syscom
# INCLUDES += -I$(MIDDLEWARE_PATH)/crypto/microecc
# INCLUDES += -I$(MIDDLEWARE_PATH)/crypto/curve25519
INCLUDES += -I$(PROJ_ROOT_PATH)/bus/i2c
INCLUDES += -I$(PROJ_ROOT_PATH)/bus/spi
INCLUDES += -I$(PROJ_ROOT_PATH)/driver/userspace/pca9685
INCLUDES += -I$(PROJ_ROOT_PATH)/driver/userspace/ps2

# Option for development
CFLAGS = -g -O2 -Wall -std=gnu99
# Option for release
# CFLAGS = -O -Wall

# CFLAGS += -D$(OS)

# include $(PROJ_ROOT_PATH)/config.mk


$(OUTPUT): $(OBJS)
	$(AT)echo "LIBS: $(LIBS)"
	$(AT)echo "LIBS_PATH: $(LIBS_PATH)"
	$(AT)$(CC) $^ -o $(BIN_PATH)$@ $(INCLUDES) $(LIBS) -L$(LIBS_PATH)
# 	$(AT)echo "$(OUTPUT) linking done"

# $(OBJS): $(SRCS)
$(OBJS):%.o:%.c
# 	$(AT)echo "SRCS: $(SRCS)"
# 	$(AT)echo "OBJS: $(OBJS)"
	$(AT)$(CC) -c $< $(CFLAGS) $(INCLUDES) -o $@
# 	$(AT)echo "$(OBJS) compiling done"


.PHONY: clean
clean:
	$(AT)-rm -rf $(OBJS)

